package Wallpaper::Execute::BlurryTerminal;
$VERSION = sprintf "%.3f", 1 + substr(q$Revision: 159 $,9)/1000;

package Wallpaper::Execute;

use Image::Magick;
use Wallpaper::Configuration qw( %datastore );

=item * doterminal

doterminal accepts one parameter, the complete path to the photo to manipulate.
It then determines if a valid imagemagick object exists on which to operate and
assigns a reference to it.  It calls colorscheme to grab a scheme of colors, and
begins to colorize and blur the image. 

It's final task is to clean out old terminal images and write out the new one.

=cut

sub doterminal {
    my ( $display, $in_image ) = @_;

    my $display_config = Wallpaper::Configuration->display( $display );
    my $urxvt          = Wallpaper::Configuration->urxvt( $display );
    my $colorscheme    = $datastore{ $display }{ 'scheme' };
    my $backcolor      = "#" . $colorscheme->{ 'primary' }{ 'base' };     # Fill color = picture mean
    my $bordercolor    = "#" . $colorscheme->{ 'primary' }{ 'dark' };     # Border color is a slightly darker picture mean
    my $image          = $in_image->Clone();                              # So we dont modify original input image

    # Terminal Backgrounds, blur effect looks very cool
    $image->Resize( geometry => "!" . $display_config->{ 'resolution' } );    # Just in case
    $image->Colorize( fill    => $backcolor,
                      opacity => $urxvt->{ 'theme_op' } );
    $image->Colorize( fill    => '#000000',
                      opacity => $urxvt->{ 'black_op' } );
    $image->Blur( channel => 'All',
                  sigma   => $urxvt->{ 'blur' } );

    my $urxvt_filename = $urxvt->{ 'dir' } . "/urxvt" . $display . ".xpm";

    # Write xpm apas, so we dont lose pixmap in urxvt.
    $image->Write( filename => $urxvt_filename );

    undef $image;    # Now we can clean blurred image from memory and $image array

} ## end sub doterminal

1;
